﻿using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Orm.DataEntity;
using System;
using System.ComponentModel;

namespace LM.CB.K3Cloud.Plugin
{
    /// <summary>
    /// 预算成本树形查询表单插件
    /// </summary>
    /// <remarks>
    /// 功能：1.工费制费点击链接界面
    /// 创建人：lxl
    /// 创建日期：2024-03-27
    /// </remarks>
    [Description("预算成本树形查询表单插件")]
    [Kingdee.BOS.Util.HotUpdate]
    public class BugCostSelectBillPlugin : AbstractBillPlugIn
    {
        public override void BeforeF7Select(BeforeF7SelectEventArgs e)
        {
            base.BeforeF7Select(e);
            switch (e.FieldKey.ToUpper())
            {
                case "F_RDLV_WORKAMT":
                    //获取当前产品的id
                    DynamicObject fproductObj = this.Model.GetValue("F_RDLV_CHILDID", e.Row) as DynamicObject;
                    string fProductId = Convert.ToString(fproductObj["id"]);
                    //获取年月
                    string fyear = Convert.ToString(this.Model.GetValue("F_RDLV_Year"));
                    string fmonth = Convert.ToString(this.Model.GetValue("F_RDLV_Month"));
                    ////获取组织
                    DynamicObject forgObj = this.Model.GetValue("F_RDLV_ORGID") as DynamicObject;
                    string forgid = Convert.ToString(forgObj["id"]);
                    //获取公费制费金额
                    string fworkExp = Convert.ToString(this.Model.GetValue("F_RDLV_WorkAmt", e.Row));
                    if (Convert.ToDecimal(fworkExp) > 0)
                    {
                        //打开工费制费单据界面
                        ListShowParameter listShowParameter = new ListShowParameter();
                        listShowParameter.FormId = "RDLV_GFZF";//工费制费单据标识
                        listShowParameter.MultiSelect = true;//是否支持多选
                        listShowParameter.IsLookUp = true;
                        listShowParameter.PageId = Guid.NewGuid().ToString();//页面pageid，此处可以用guid
                        listShowParameter.ParentPageId = base.View.PageId;//绑定父页面
                        listShowParameter.OpenStyle.ShowType = Kingdee.BOS.Core.DynamicForm.ShowType.Modal;
                        listShowParameter.ListFilterParameter.Filter = string.Format(
                            $" 1=1 and F_RDLV_YEAR={fyear} and F_RDLV_MONTH={fmonth} and F_RDLV_OrgId={forgid} and F_RDLV_CPBM={fProductId}");//过滤
                        this.View.ShowForm(listShowParameter);
                    }
                    break;
                default: break;
            }
        }

    }
}
